<template>
  <div class="content">
    <div class="inner">
      <u-subsection
        :list="list"
        :current="current"
        mode="subsection"
        activeColor="#d22f10"
        inactiveColor="#d22f10"
        @change="sectionChange"
      ></u-subsection>
      <div class="gift-list">
        <div class="gift-item" v-for="item in giftList" :key="item.itemId">
          <img class="prize-image" src="/static/huawei.png" />
          <div class="left">
            <div class="name">{{ item.prizeName }}</div>
            <p class="time">有效期至：{{ item.delayTime || "" }}</p>
          </div>
          <div
            class="right"
            @click="showGift(item.prizeCode)"
            v-if="item.recordStatus === '1'"
          >
            去兑换
            <u-icon name="arrow-right" color="#e9e9e9" size="12"></u-icon>
          </div>
        </div>
      </div>
      <div class="empty" v-if="giftList.length === 0">暂无数据</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "gift",
  data() {
    return {
      list: ["待兑换", "已兑换", "已过期", "全部"],
      current: 0,
      giftList: [],
    };
  },
  onLoad() {
    this.getGiftList();
  },
  methods: {
    sectionChange(index) {
      this.current = index;
      this.getGiftList();
    },
    showGift(val) {
      uni.showModal({
        title: "兑换码",
        content: val,
        showCancel: false,
      });
    },
    getGiftList() {
      this.$Api.main.lottery
        .loadLottery({
          recordStatus: this.current,
        })
        .then((res) => {
          this.giftList = res.data;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  padding: 20rpx;
  .inner {
    width: 100%;
    padding: 20rpx;
    background: #fff;
    border-radius: 10rpx;
    box-sizing: border-box;
    .gift-list {
      width: 100%;
      margin-top: 20rpx;
      border-top: 1rpx solid #e9e9e9;
      .gift-item {
        width: 100%;
        border-bottom: 1rpx solid #e9e9e9;
        padding: 24rpx;
        font-size: 26rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
        .prize-image {
          width: 50rpx;
          height: 50rpx;
          margin-right: 20rpx;
        }
        .left {
          flex: 1;
          overflow: hidden;
          .name {
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-size: 32rpx;
          }
          .time {
            color: #808080;
            font-size: 26rpx;
            margin-top: 6rpx;
          }
        }
        .right {
          margin-left: 10rpx;
          display: flex;
          justify-content: flex-end;
          align-items: center;
          color: #808080;
          white-space: nowrap;
        }
      }
    }
    .empty {
      text-align: center;
      margin: 20rpx 0;
      color: #808080;
      font-size: 26rpx;
    }
  }
}
</style>
